package world.ztomorrow.novel.listen;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import world.ztomorrow.novel.dao.mapper.BookInfoMapper;
import world.ztomorrow.novel.dao.po.BookInfo;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class SearchListen {

    private final BookInfoMapper bookInfoMapper;

    @GetMapping("/search/books")
    List<BookInfo> listAllBook(){
        return bookInfoMapper.selectList(new LambdaQueryWrapper<BookInfo>()
                .gt(BookInfo::getWordCount, 0));
    }

    @GetMapping("/search/book")
    BookInfo getBookById(@RequestParam("id") Long id){
        return bookInfoMapper.selectById(id);
    }
}
